from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
class Base():

    def __init__(self, driver):
        self.driver = driver
    def open_url(self, url):
        self.driver.get(url)
    def find_element(self, loc):
       return self.driver.find_element(*loc)
    # 封装点击事件
    def click(self, loc):
        self.find_element(loc).click()
    # 封装输入方法
    def send_keys(self, loc, text):
        self.find_element(loc).send_keys(text)
    # 鼠标的封装
    # 封装鼠标双击
    def double_click(self, loc):
        ActionChains(self.driver).double_click(self.find_element(loc)).perform()
    # 封装鼠标三击
    def three_click(self, loc):
        ActionChains(self.driver).double_click(self.find_element(loc)).click(self.find_element(loc)).perform()
    # 封装鼠标右击
    def context_click(self, loc):
        ActionChains(self.driver).context_click(loc).perform()
        # 封装鼠标悬停
    def move_to_element(self, loc):
        ActionChains(self.driver).move_to_element(self.find_element(loc)).perform()
    # 封裝鼠标拖拽
    def drag_and_drop(self, loc, x,y):
        ActionChains(self.driver).drag_and_drop_by_offset(self.find_element(loc), x,y).perform()
    # 封装鼠标按住不放
    def click_and_hold(self, loc):
        ActionChains(self.driver).click_and_hold(self.find_element(loc)).perform()

    # 键盘事件的封装
    # 封装回车事件
    def keys_enter(self,loc):
        self.send_keys(loc,Keys.ENTER)
    # 封装tab
    def keys_tab(self,loc):
        self.send_keys(loc,Keys.TAB)
    # 封装DELETE
    def keys_delete(self,loc):
        self.send_keys(loc,Keys.DELETE)
    # 封装BACKSPACE
    def keys_backspace(self,loc):
        self.send_keys(loc, Keys.BACKSPACE)
    # 封装space
    def keys_space(self,loc):
        self.send_keys(loc,Keys.SPACE)
    # 封装Home
    def keys_home(self,loc):
        self.send_keys(loc,Keys.HOME)
    # 封装up
    def keys_up(self,loc):
        self.send_keys(loc,Keys.UP)
    # 封装right
    def keys_right(self, loc):
        self.send_keys(loc, Keys.RIGHT)
    # 封装left
    def keys_left(self,loc):
        self.send_keys(loc,Keys.LEFT)